package com.controller;

import com.pojo.FinishedProductInfo;
import com.service.iter.IFinishedProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 成品控制器
 *
 * @author 蔡文欣
 * @date 2023/07/01 09:13:57
 */
@RestController
@RequestMapping("finished/")
public class FinishedProductController {
    /**
     * 成品服务
     */
    @Autowired
    public IFinishedProductService iFinishedProductService;

    /**
     * 获取成品信息
     *
     * @return {@link List}<{@link FinishedProductInfo}>
     */
    @GetMapping("getFinishedProductInfo")
    public List<FinishedProductInfo> getFinishedProductInfo() {
        return iFinishedProductService.getFinishedProductInfo();
    }

    /**
     * 更新实际
     *
     * @param batchNumber     成品批次
     * @param finishedProductActual 成品实际
     * @return {@link String}
     */
    @GetMapping("updateActual")
    public String  updateActual(String batchNumber,Long finishedProductActual) {
//        Long finishedProductId = Long.parseLong(request.getParameter("finishedProductId"));
//        Long finishedProductActual = Long.parseLong(request.getParameter("finishedProductActual"));
        int i = iFinishedProductService.updateActual(batchNumber, finishedProductActual);
        if (i>0){
            return "success";
        }
        return "false";
    }

//    /**
//     * 更新实际
//     *
//     * @return {@link String}
//     */
//    @GetMapping("updateBatch")
//    public String  updateBatch(String random, HttpServletRequest request,Long finishedProductId) {
//        System.out.println("11111111");
//        System.out.println(random+finishedProductId);
//        System.out.println("11111111");
//        random =request.getParameter("random");
//        int i = iFinishedProductService.updateBatch(random,finishedProductId);
//        if (i>0){
//            return "success";
//        }
//        return "false";
//    }


    @GetMapping("updateCause")
    public String  updateCause(String batchNumber,Long finishedProductActual,String cause) {
        int i = iFinishedProductService.updateCause(batchNumber, finishedProductActual,cause);
        if (i>0){
            return "success";
        }
        return "false";
    }

}
